// ************************************************************************ //
// The types declared in this file were generated from data read from the
// WSDL File described below:
// WSDL     : http://zolm.gscpe.com.br/zolm/index.php?wsdl
//  >Import : http://zolm.gscpe.com.br/zolm/index.php?wsdl>0
// Encoding : UTF-8
// Version  : 1.0
// (02/11/2014 15:59:49 - - $Rev: 56641 $)
// ************************************************************************ //

unit zolmws;

interface

uses InvokeRegistry, SOAPHTTPClient, Types, XSBuiltIns;

type

  // ************************************************************************ //
  // The following types, referred to in the WSDL document are not being represented
  // in this file. They are either aliases[@] of other types represented or were referred
  // to but never[!] declared in the document. The types from the latter category
  // typically map to predefined/known XML or Embarcadero types; however, they could also 
  // indicate incorrect WSDL documents that failed to declare or import a schema type.
  // ************************************************************************ //
  // !:integer         - "http://www.w3.org/2001/XMLSchema"[]
  // !:string          - "http://www.w3.org/2001/XMLSchema"[]


  // ************************************************************************ //
  // Namespace : http://zolm.gscpe.com.br/soap/zolm
  // soapAction: http://zolm.gscpe.com.br/zolm/index.php/%operationName%
  // transport : http://schemas.xmlsoap.org/soap/http
  // style     : rpc
  // use       : encoded
  // binding   : zolmBinding
  // service   : zolm
  // port      : zolmPort
  // URL       : http://zolm.gscpe.com.br/zolm/index.php
  // ************************************************************************ //
  zolmPortType = interface(IInvokable)
  ['{4FDFFCF3-7A2B-96D3-CB91-8C1E5A023896}']
    function  getCryptographicKey(const aCpfCnpj: string; const aSenha: string; const aSoftwareId: Int64): string; stdcall;
    function  getPublicKey(const aCpfCnpj: string; const aSenha: string): string; stdcall;
    function  validateHardware(const aCpfCnpj: string; const aSenha: string; const aSoftwareId: Int64; const aHardwareId: string): Int64; stdcall;
    function  registerHardware(const aCpfCnpj: string; const aSenha: string; const aSoftwareId: Int64; const aHardwareId: string; const aOtherInformations: string): Int64; stdcall;
    function  requestSerial(const aCpfCnpj: string; const aSenha: string; const aSoftwareId: Int64; const aHardwareId: string; const aOtherInformations: string): Int64; stdcall;
    function  getNewVersion(const aSoftwareId: Int64; const aCurrentVersion: string; const aCompareMode: string): string; stdcall;
  end;

function GetzolmPortType(UseWSDL: Boolean=System.False; Addr: string=''; HTTPRIO: THTTPRIO = nil): zolmPortType;

implementation

uses SysUtils, System.Classes;

type
  TEH = class
  public
    procedure DoBeforeExecute(const aMethodName: String; aSoapRequest: TStream);
  end;

function GetzolmPortType(UseWSDL: Boolean; Addr: string; HTTPRIO: THTTPRIO): zolmPortType;
const
  defWSDL = 'http://zolm.gscpe.com.br/zolm/index.php?wsdl';
  defURL  = 'http://zolm.gscpe.com.br/zolm/index.php';
  defSvc  = 'zolm';
  defPrt  = 'zolmPort';
var
  RIO: THTTPRIO;
  EH: TEH;
begin
  Result := nil;
  if (Addr = '') then
  begin
    if UseWSDL then
      Addr := defWSDL
    else
      Addr := defURL;
  end;

  if HTTPRIO = nil then
    RIO := THTTPRIO.Create(nil)
  else
    RIO := HTTPRIO;

  EH := TEH.Create;
  try
    ////////////////////////////////////////////////////////////////////////////
    RIO.OnBeforeExecute := EH.DoBeforeExecute;
    ////////////////////////////////////////////////////////////////////////////
    Result := (RIO as zolmPortType);
    if UseWSDL then
    begin
      RIO.WSDLLocation := Addr;
      RIO.Service := defSvc;
      RIO.Port := defPrt;
    end
    else
      RIO.URL := Addr;
  finally
    EH.Free;

    if (Result = nil) and (HTTPRIO = nil) then
      RIO.Free;
  end;
end;

{ TEH }

procedure TEH.DoBeforeExecute(const aMethodName: String; aSoapRequest: TStream);
begin
  with TStringList.Create do
    try
      aSoapRequest.Position := 0;
      LoadFromStream(aSoapRequest);
      //SaveToFile('d:\' + aMethodName + 'Antes.txt');
      Text := StringReplace(Text,'&amp;','&#38;',[rfReplaceAll]);
      Text := StringReplace(Text,'&lt;','&#60;',[rfReplaceAll]);
      Text := StringReplace(Text,'&gt;','&#62;',[rfReplaceAll]);
      Text := StringReplace(Text,'&apos;','&#39;',[rfReplaceAll]);
      Text := StringReplace(Text,'&quot;','&#34;',[rfReplaceAll]);
      aSoapRequest.Position := 0;
      aSoapRequest.Size := Length(Text);
      SaveToStream(aSoapRequest);
      //SaveToFile('d:\' + aMethodName + 'Depois.txt');
    finally
      Free;
    end;
end;

initialization
  { zolmPortType }
  InvRegistry.RegisterInterface(TypeInfo(zolmPortType), 'http://zolm.gscpe.com.br/soap/zolm', 'UTF-8');
  InvRegistry.RegisterDefaultSOAPAction(TypeInfo(zolmPortType), 'http://zolm.gscpe.com.br/zolm/index.php/%operationName%');

end.